//
//  DiscoverViewController.swift
//  ShangHaiWeiBo
//
//  Created by 蔡杰 on 16/2/22.
//  Copyright © 2016年 蔡杰. All rights reserved.
//

import UIKit
private let CZDiscoverCellID = "CZDiscoverCellID"
class DiscoverViewController: baseViewController {

    override func viewDidLoad() {
        setWard()
        
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        tableView?.registerClass(UITableViewCell.self, forCellReuseIdentifier: CZDiscoverCellID)
        visitor?.setUpInfo("visitordiscover_image_message", messageImageName: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    override func loadData() {
        
        refreshControl?.beginRefreshing()
        
        print("%@",[NSThread .currentThread()])
        let when = dispatch_time(DISPATCH_TIME_NOW, Int64(Double(NSEC_PER_SEC) * 1.0))
        dispatch_after(when, dispatch_get_main_queue()) { () -> Void in
            
            self.data += 10
            
            // 结束刷新
            self.refreshControl?.endRefreshing()
                        
            self.tableView?.reloadData()
        }
    }

    private var data = 0
   

}

extension DiscoverViewController {

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return data
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCellWithIdentifier(CZDiscoverCellID, forIndexPath: indexPath)
        
        cell.textLabel?.text = "\(indexPath.row)"
        return cell
    }
}